package com.gw.booking.service;

import com.gw.booking.entity.OrderForm;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderFormService {
    @Autowired
    private SessionFactory sessionFactory;

    public String txGetFormId(Integer orderId){
        Session session = sessionFactory.getCurrentSession();
        String hql = " from OrderForm where orderId = :orderId ";
        List<OrderForm> orderFormList = session.createQuery(hql)
                .setParameter("orderId",orderId)
                .list();
        if(orderFormList==null||orderFormList.size()<1){
            return null;
        }
        String formId = orderFormList.get(0).getFormId();
        session.delete(orderFormList.get(0));
        return formId;
    }
}
